var mobiscroll = mobiscroll || {};
(function(n, h, f) {
    var e, g = mobiscroll,
        a = g.$,
        t = a.extend,
        k = g.classes,
        c = g.util,
        l = c.prefix,
        d = c.jsPrefix,
        b = c.getCoord,
        q = c.testTouch,
        o = c.vibrate,
        j = 1,
        i = function() {},
        r = n.requestAnimationFrame || function(a) {
            a();
        },
        s = n.cancelAnimationFrame || i,
        m = 'webkitAnimationEnd animationend',
        p = 'transparent';
    k.ListView = function(bB, bH) {
        var R, ak, ac, E, aM, bx, bw, x, M, K, aJ, at, bA, I, a3, bD, aq, bs, J, a2, P, T, a6, bq, b8, bj, bh, A, as, aw, U, bp, aR, W, bt, bm, $, aY, aG, bk, bI, aV, b9, al, N, z, ae, u, D, w, b6, bQ, aA, az, aP, L, Y, a0, b0, b1, aL, aH, bC, ba, Q, H, Z, a1, aD, bg, aB, v, ab, a7, b3, b5, ar, bJ, bM, ax, au, S, V, aS, bu, aT, aF, av, y, af, ay, aQ, B, aa, ai, b7, g = this,
            G = bB,
            C = a(G),
            X = 0,
            a4 = 0,
            F = 0,
            ap = {},
            aE = {},
            O = {};

        function bF() {
            aD = false;
            aL = false;
            E = 0;
            bJ = 0;
            bM = new Date();
            ae = K.width();
            bA = am(K);
            w = bA.index(u);
            D = u[0].offsetHeight;
            F = u[0].offsetTop;
            y = af[u.attr('data-type') || 'defaults'];
            ar = y.stages;
        }

        function bP(c) {
            var f;
            if (c.type === 'touchstart') {
                aH = true;
                clearTimeout(bC);
            }
            if (q(c, this) && !R && !X && !e && !aN && mobiscroll.running) {
                R = true;
                aM = true;
                ax = b(c, 'X');
                au = b(c, 'Y');
                J = 0;
                a2 = 0;
                u = a(this);
                f = u;
                bF();
                aT = v.onItemTap || y.tap || u.hasClass('mbsc-lv-parent') || u.hasClass('mbsc-lv-back');
                bQ = C.offset().top;
                b6 = u.offset().top;
                if (aT) {
                    ac = setTimeout(function() {
                        f.addClass('mbsc-lv-item-active');
                        A('onItemActivate', {
                            target: f[0],
                            domEvent: c
                        });
                    }, 120);
                }
                if (g.sortable && !u.hasClass('mbsc-lv-back')) {
                    if (!g.sortable.group) {
                        b0 = u.nextUntil('.mbsc-lv-gr-title').filter('.mbsc-lv-item');
                        ba = u.prevUntil('.mbsc-lv-gr-title').filter('.mbsc-lv-item');
                    }
                    az = (!g.sortable.group ? ba.length ? ba.eq(-1) : u : K.children('li').eq(0))[0].offsetTop - F;
                    aA = (!g.sortable.group ? b0.length ? b0.eq(-1) : u : K.children('li').eq(-1))[0].offsetTop - F;
                    if (g.sortable.handle) {
                        if (a(c.target).hasClass('mbsc-lv-handle')) {
                            clearTimeout(ac);
                            if (d === 'Moz') {
                                c.preventDefault();
                                aX();
                            } else {
                                av = setTimeout(function() {
                                    aX();
                                }, 100);
                            }
                        }
                    } else {
                        av = setTimeout(function() {
                            as.appendTo(u);
                            as[0].style[d + 'Animation'] = 'mbsc-lv-fill ' + (v.sortDelay - 100) + 'ms linear';
                            clearTimeout(b8);
                            clearTimeout(ac);
                            aM = false;
                            av = setTimeout(function() {
                                as[0].style[d + 'Animation'] = '';
                                aX();
                            }, v.sortDelay - 80);
                        }, 80);
                    }
                }
                if (c.type == 'mousedown') {
                    a(h).on('mousemove', aU).on('mouseup', ao);
                }
            }
        }

        function aU(c) {
            var d = false,
                e = true;
            if (R) {
                bj = b(c, 'X');
                bh = b(c, 'Y');
                J = bj - ax;
                a2 = bh - au;
                clearTimeout(b8);
                if (!a6 && !V && !ab && !u.hasClass('mbsc-lv-back')) {
                    if (Math.abs(a2) > 10) {
                        ab = true;
                        c.type = c.type == 'mousemove' ? 'mouseup' : 'touchend';
                        ao(c);
                        clearTimeout(ac);
                    } else if (Math.abs(J) > 7) {
                        bL();
                    } else {
                        if (c.type === 'touchmove') {
                            b8 = setTimeout(function() {
                                c.type = 'touchend';
                                ao(c);
                            }, 300);
                        }
                    }
                }
                if (V) {
                    c.preventDefault();
                    E = J / ae * 100;
                    aW();
                } else if (a6) {
                    c.preventDefault();
                    var i, f = B.scrollTop(),
                        a = Math.max(az, Math.min(a2 + ai, aA)),
                        h = W ? b6 - b7 + f - ai : b6;
                    if (aa + f < h + a + D) {
                        B.scrollTop(h + a - aa + D);
                        i = true;
                    } else if (h + a < f) {
                        B.scrollTop(h + a);
                        i = true;
                    }
                    if (i) {
                        ai += B.scrollTop() - f;
                    }
                    if (Y) {
                        if (g.sortable.multiLevel && L.hasClass('mbsc-lv-parent')) {
                            if (F + D / 4 + a > Y) {
                                d = true;
                            } else if (F + D - D / 4 + a > Y) {
                                P = L.addClass('mbsc-lv-item-hl');
                                e = false;
                            }
                        } else if (F + D / 2 + a > Y) {
                            if (L.hasClass('mbsc-lv-back')) {
                                if (g.sortable.multiLevel) {
                                    T = L.addClass('mbsc-lv-item-hl');
                                    e = false;
                                }
                            } else {
                                d = true;
                            }
                        }
                        if (d) {
                            Q.insertAfter(L);
                            H = L;
                            L = aO(L, 'next');
                            Z = Y;
                            Y = L.length && L[0].offsetTop;
                            M++;
                        }
                    }
                    if (!d && Z) {
                        if (g.sortable.multiLevel && H.hasClass('mbsc-lv-parent')) {
                            if (F + D - D / 4 + a < Z) {
                                d = true;
                            } else if (F + D / 4 + a < Z) {
                                P = H.addClass('mbsc-lv-item-hl');
                                e = false;
                            }
                        } else if (F + D / 2 + a < Z) {
                            if (H.hasClass('mbsc-lv-back')) {
                                if (g.sortable.multiLevel) {
                                    T = H.addClass('mbsc-lv-item-hl');
                                    e = false;
                                }
                            } else {
                                d = true;
                            }
                        }
                        if (d) {
                            Q.insertBefore(H);
                            L = H;
                            H = aO(H, 'prev');
                            Y = Z;
                            Z = H.length && H[0].offsetTop + H[0].offsetHeight;
                            M--;
                        }
                    }
                    if (e) {
                        if (P) {
                            P.removeClass('mbsc-lv-item-hl');
                            P = false;
                        }
                        if (T) {
                            T.removeClass('mbsc-lv-item-hl');
                            T = false;
                        }
                    }
                    if (d) {
                        A('onSortChange', [u, M]);
                    }
                    br(u, a);
                    A('onSort', [u, M]);
                } else if (Math.abs(J) > 5 || Math.abs(a2) > 5) {
                    b2();
                }
            }
        }

        function ao(e) {
            var f, b, d, i, j = u;
            if (R) {
                R = false;
                b2();
                if (e.type == 'mouseup') {
                    a(h).off('mousemove', aU).off('mouseup', ao);
                }
                if (!ab) {
                    bC = setTimeout(function() {
                        aH = false;
                    }, 300);
                }
                if (V || ab || a6) {
                    aL = true;
                }
                if (V) {
                    bf();
                } else if (a6) {
                    d = K;
                    if (P) {
                        a9(u.detach());
                        b = O[P.attr('data-ref')];
                        M = am(b.child).length;
                        P.removeClass('mbsc-lv-item-hl');
                        if (v.navigateOnDrop) {
                            bc(P, function() {
                                g.add(null, u, null, null, P, true);
                                aj(u);
                                an(u, w, d, true);
                            });
                        } else {
                            g.add(null, u, null, null, P, true);
                            an(u, w, d, true);
                        }
                    } else if (T) {
                        a9(u.detach());
                        b = O[T.attr('data-back')];
                        M = am(b.parent).index(b.item) + 1;
                        T.removeClass('mbsc-lv-item-hl');
                        if (v.navigateOnDrop) {
                            bc(T, function() {
                                g.add(null, u, M, null, K, true);
                                aj(u);
                                an(u, w, d, true);
                            });
                        } else {
                            g.add(null, u, M, null, b.parent, true);
                            an(u, w, d, true);
                        }
                    } else {
                        f = Q[0].offsetTop - F;
                        br(u, f, Math.abs(f - Math.max(az, Math.min(a2 + ai, aA))) * 6, function() {
                            a9(u);
                            u.insertBefore(Q);
                            an(u, w, d, M !== w);
                        });
                    }
                    a6 = false;
                } else if (!ab && Math.abs(J) < 5 && Math.abs(a2) < 5) {
                    if (y.tap) {
                        i = y.tap.call(G, {
                            target: u,
                            index: w,
                            domEvent: e
                        }, g);
                    }
                    if (aT) {
                        if (e.type === 'touchend') {
                            c.preventClick();
                        }
                        u.addClass('mbsc-lv-item-active');
                        A('onItemActivate', {
                            target: u[0],
                            domEvent: e
                        });
                    }
                    i = A('onItemTap', {
                        target: u[0],
                        index: w,
                        domEvent: e
                    });
                    if (i !== false) {
                        bc(u);
                    }
                }
                clearTimeout(ac);
                setTimeout(function() {
                    j.removeClass('mbsc-lv-item-active');
                    A('onItemDeactivate', {
                        target: j[0]
                    });
                }, 100);
                ab = false;
                I = null;
            }
        }

        function bL() {
            V = a8(y.swipe, {
                target: u[0],
                index: w,
                direction: J > 0 ? 'right' : 'left'
            });
            if (V) {
                b2();
                clearTimeout(ac);
                if (y.actions) {
                    ak = bG(y, J);
                    aP.html(y.icons).show().children().css('width', ak + '%');
                    N.hide();
                    a('.mbsc-lv-ic-m', z).removeClass('mbsc-lv-ic-disabled');
                    a(y.leftMenu).each(bl);
                    a(y.rightMenu).each(bl);
                } else {
                    N.show();
                    aP.hide();
                    a3 = y.start + (J > 0 ? 0 : 1);
                    a1 = ar[a3 - 1];
                    a0 = ar[a3];
                }
                u.addClass('mbsc-lv-item-swiping').removeClass('mbsc-lv-item-active');
                aF.css('line-height', D + 'px');
                z.css({
                    top: F,
                    height: D,
                    backgroundColor: bE(J)
                }).addClass('mbsc-lv-stage-c-v').appendTo(K.parent());
                if (v.iconSlide) {
                    u.append(N);
                }
                A('onSlideStart', {
                    target: u[0],
                    index: w
                });
            }
        }

        function aW() {
            var a = false;
            if (!aB) {
                if (y.actions) {
                    z.attr('class', 'mbsc-lv-stage-c-v mbsc-lv-stage-c mbsc-lv-' + (E < 0 ? 'right' : 'left'));
                } else {
                    if (a1 && E <= a1.percent) {
                        a3--;
                        a0 = a1;
                        a1 = ar[a3];
                        a = true;
                    } else if (a0 && E >= a0.percent) {
                        a3++;
                        a1 = a0;
                        a0 = ar[a3];
                        a = true;
                    }
                    if (a) {
                        I = E > 0 ? a1 : a0;
                        if (I) {
                            aK(I, v.iconSlide);
                            A('onStageChange', {
                                target: u[0],
                                index: w,
                                stage: I
                            });
                        }
                    }
                }
                if (!a7) {
                    aB = true;
                    bg = r(bo);
                }
            }
        }

        function bf(b) {
            var f, g, d, c = false,
                i = true;
            s(bg);
            aB = false;
            if (!a7) {
                bo();
            }
            if (y.actions) {
                if (Math.abs(E) > 10 && ak) {
                    ah(u, E < 0 ? -ak : ak, 200);
                    c = true;
                    e = true;
                    bx = u;
                    bw = w;
                    a(h).on('touchstart.mbsc-lv-conf mousedown.mbsc-lv-conf', function(a) {
                        a.preventDefault();
                        aI(u, true, b);
                    });
                }
            } else if (E) {
                if (v.quickSwipe && !a7) {
                    d = new Date() - bM;
                    f = d < 300 && J < -50;
                    g = d < 300 && J > 50;
                    if (f) {
                        aD = true;
                        I = y.left;
                        aK(I, v.iconSlide);
                    } else if (g) {
                        aD = true;
                        I = y.right;
                        aK(I, v.iconSlide);
                    }
                }
                if (I && I.action) {
                    bs = a8(I.disabled, {
                        target: u[0],
                        index: w
                    });
                    if (!bs) {
                        c = true;
                        e = a7 || a8(I.confirm, {
                            target: u[0],
                            index: w
                        });
                        if (e) {
                            ah(u, (E < 0 ? -1 : 1) * N[0].offsetWidth * 100 / ae, 200, true);
                            bn(I, u, w, false, b);
                        } else {
                            a$(I, u, w, b);
                        }
                    }
                }
            }
            if (!c) {
                aI(u, i, b);
            }
            V = false;
        }

        function aX() {
            a6 = true;
            P = false;
            T = false;
            ai = 0;
            M = w;
            if (v.vibrate) {
                o();
            }
            L = aO(u, 'next');
            Y = L.length && L[0].offsetTop;
            H = aO(u, 'prev');
            Z = H.length && H[0].offsetTop + H[0].offsetHeight;
            Q.height(D).insertAfter(u);
            u.css({
                top: F
            }).addClass('mbsc-lv-item-dragging').removeClass('mbsc-lv-item-active').appendTo(bq);
            A('onSortStart', {
                target: u[0],
                index: M
            });
        }

        function an(a, b, c, d) {
            a.removeClass('mbsc-lv-item-dragging');
            Q.remove();
            A('onSortEnd', {
                target: a[0],
                index: M
            });
            if (v.vibrate) {
                o();
            }
            if (d) {
                g.addUndoAction(function(d) {
                    g.move(a, b, null, d, c, true);
                }, true);
                A('onSortUpdate', {
                    target: a[0],
                    index: M
                });
            }
        }

        function bi() {
            if (!aH) {
                clearTimeout(bI);
                if (e) {
                    a(h).trigger('touchstart');
                }
                if (aY) {
                    g.close($, aG);
                    aY = false;
                    $ = null;
                }
            }
        }

        function aZ() {
            clearTimeout(bD);
            bD = setTimeout(function() {
                aa = B[0].innerHeight || B.innerHeight();
                b7 = W ? B.offset().top : 0;
                if (R) {
                    F = u[0].offsetTop;
                    D = u[0].offsetHeight;
                    z.css({
                        top: F,
                        height: D
                    });
                }
            }, 200);
        }

        function bO() {
            if (a6 || !R) {
                var d, e = B.scrollTop(),
                    c = C.offset().top,
                    f = C[0].offsetHeight,
                    b = W ? B.offset().top : e;
                a('.mbsc-lv-gr-title', C).each(function(e, c) {
                    if (a(c).offset().top < b) {
                        d = c;
                    }
                });
                if (c < b && c + f > b) {
                    U.show().empty().append(a(d).clone());
                } else {
                    U.hide();
                }
            }
        }

        function bl(c, b) {
            if (a8(b.disabled, {
                    target: u[0],
                    index: w
                })) {
                a('.mbsc-ic-' + b.icon, z).addClass('mbsc-lv-ic-disabled');
            }
        }

        function a$(c, b, d, h) {
            var e, f = {
                icon: 'undo2',
                text: v.undoText,
                color: '#b1b1b1',
                action: function() {
                    g.undo();
                }
            };
            if (c.undo) {
                g.startActionTrack();
                if (a.isFunction(c.undo)) {
                    g.addUndoAction(function() {
                        c.undo.call(G, b, g, d);
                    });
                }
                ay = b.attr('data-ref');
            }
            e = c.action.call(G, {
                target: b[0],
                index: d
            }, g);
            if (c.undo) {
                g.endActionTrack();
                if (e !== false) {
                    ah(b, +b.attr('data-pos') < 0 ? -100 : 100, 200);
                }
                Q.height(D).insertAfter(b);
                b.css('top', F).addClass('mbsc-lv-item-undo');
                aP.hide();
                N.show();
                z.append(N);
                aK(f);
                bn(f, b, d, true, h);
            } else {
                aI(b, e, h);
            }
        }

        function bn(k, d, l, f, g) {
            var i, j;
            e = true;
            a(h).off('.mbsc-lv-conf').on('touchstart.mbsc-lv-conf mousedown.mbsc-lv-conf', function(a) {
                a.preventDefault();
                if (f) {
                    bv(d);
                }
                aI(d, true, g);
            });
            if (!aq) {
                N.off('.mbsc-lv-conf').on('touchstart.mbsc-lv-conf mousedown.mbsc-lv-conf', function(a) {
                    a.stopPropagation();
                    i = b(a, 'X');
                    j = b(a, 'Y');
                }).on('touchend.mbsc-lv-conf mouseup.mbsc-lv-conf', function(a) {
                    a.preventDefault();
                    if (a.type === 'touchend') {
                        c.preventClick();
                    }
                    if (Math.abs(b(a, 'X') - i) < 10 && Math.abs(b(a, 'Y') - j) < 10) {
                        a$(k, d, l, g);
                        if (f) {
                            aQ = null;
                            bv(d);
                        }
                    }
                });
            }
        }

        function bo() {
            ah(u, bJ + J * 100 / ae);
            aB = false;
        }

        function aI(b, d, c) {
            a(h).off('.mbsc-lv-conf');
            N.off('.mbsc-lv-conf');
            if (d !== false) {
                ah(b, 0, b.attr('data-pos') !== '0' ? 200 : 0, false, function() {
                    b4(b, c);
                    a9(b);
                });
            } else {
                b4(b, c);
            }
            e = false;
        }

        function ah(b, a, c, f, e) {
            a = Math.max(V == 'right' ? 0 : -100, Math.min(a, V == 'left' ? 0 : 100));
            S = b[0].style;
            b.attr('data-pos', a);
            S[d + 'Transform'] = 'translate3d(' + (f ? ae * a / 100 + 'px' : a + '%') + ',0,0)';
            S[d + 'Transition'] = l + 'transform ' + (c || 0) + 'ms';
            if (e) {
                X++;
                setTimeout(function() {
                    e();
                    X--;
                }, c);
            }
            E = a;
        }

        function br(e, a, b, c) {
            a = Math.max(az, Math.min(a, aA));
            S = e[0].style;
            S[d + 'Transform'] = 'translate3d(0,' + a + 'px,0)';
            S[d + 'Transition'] = l + 'transform ' + (b || 0) + 'ms ease-out';
            if (c) {
                X++;
                setTimeout(function() {
                    c();
                    X--;
                }, b);
            }
        }

        function b2() {
            clearTimeout(av);
            if (!aM && g.sortable) {
                aM = true;
                as.remove();
            }
        }

        function aK(a, c) {
            var b = a8(a.text, {
                target: u[0],
                index: w
            }) || '';
            if (a8(a.disabled, {
                    target: u[0],
                    index: w
                })) {
                z.addClass('mbsc-lv-ic-disabled');
            } else {
                z.removeClass('mbsc-lv-ic-disabled');
            }
            z.css('background-color', a.color || (a.percent === 0 ? bE(E) : p));
            N.attr('class', 'mbsc-lv-ic-c mbsc-lv-ic-' + (c ? 'move-' : '') + (E < 0 ? 'right' : 'left'));
            al.attr('class', ' mbsc-lv-ic-s mbsc-lv-ic mbsc-ic mbsc-ic-' + (a.icon || 'none'));
            aF.attr('class', 'mbsc-lv-ic-text' + (a.icon ? '' : ' mbsc-lv-ic-text-only') + (b ? '' : ' mbsc-lv-ic-only')).html(b || '&nbsp;');
            if (v.animateIcons) {
                if (aD) {
                    al.addClass('mbsc-lv-ic-v');
                } else {
                    setTimeout(function() {
                        al.addClass('mbsc-lv-ic-a');
                    }, 10);
                }
            }
        }

        function b4(a, b) {
            if (!R) {
                al.attr('class', 'mbsc-lv-ic-s mbsc-lv-ic mbsc-ic mbsc-ic-none');
                z.attr('style', '').removeClass('mbsc-lv-stage-c-v');
                aF.html('');
            }
            z.removeClass('mbsc-lv-left mbsc-lv-right');
            if (a) {
                A('onSlideEnd', {
                    target: a[0],
                    index: w
                });
                if (b) {
                    b();
                }
            }
        }

        function bv(a) {
            a.css('top', '').removeClass('mbsc-lv-item-undo');
            if (aQ) {
                g.animate(Q, 'collapse', function() {
                    Q.remove();
                });
            } else {
                Q.remove();
            }
            b4();
            ay = null;
            aQ = null;
        }

        function a9(a) {
            S = a[0].style;
            S[d + 'Transform'] = '';
            S[d + 'Transition'] = '';
            S.top = '';
            a.removeClass('mbsc-lv-item-swiping');
        }

        function a8(b, c) {
            return a.isFunction(b) ? b.call(this, c, g) : b;
        }

        function by(b) {
            var c;
            if (!b.attr('data-ref')) {
                c = j++;
                b.attr('data-ref', c);
                O[c] = {
                    item: b,
                    child: b.children('ul,ol'),
                    parent: b.parent(),
                    ref: b.parent()[0] === G ? null : b.parent().parent().attr('data-ref')
                };
            }
            b.addClass('mbsc-lv-item');
            if (g.sortable.handle && b.attr('data-role') != 'list-divider' && !b.children('.mbsc-lv-handle-c').length) {
                b.append(bt);
            }
            if (v.enhance && !b.hasClass('mbsc-lv-item-enhanced')) {
                var d = b.attr('data-icon'),
                    e = b.find('img').eq(0).addClass('mbsc-lv-img');
                if (e.is(':first-child')) {
                    b.addClass('mbsc-lv-img-' + (v.rtl ? 'right' : 'left'));
                } else if (e.length) {
                    b.addClass('mbsc-lv-img-' + (v.rtl ? 'left' : 'right'));
                }
                b.addClass('mbsc-lv-item-enhanced').children().each(function(c, b) {
                    b = a(b);
                    if (b.is('p, h1, h2, h3, h4, h5, h6')) {
                        b.addClass('mbsc-lv-txt');
                    }
                });
                if (d) {
                    b.addClass('mbsc-lv-item-ic-' + (b.attr('data-icon-align') || (v.rtl ? 'right' : 'left'))).append('<div class="mbsc-lv-item-ic mbsc-ic mbsc-ic-' + d + '"></div');
                }
            }
        }

        function bz(b) {
            a('li', b).not('.mbsc-lv-item').each(function() {
                by(a(this));
            });
            a('li[data-role="list-divider"]', b).removeClass('mbsc-lv-item').addClass('mbsc-lv-gr-title');
            a('ul,ol', b).not('.mbsc-lv').addClass('mbsc-lv').prepend(aV).parent().addClass('mbsc-lv-parent').prepend(b9);
            a('.mbsc-lv-back', b).each(function() {
                a(this).attr('data-back', a(this).parent().parent().attr('data-ref'));
            });
        }

        function am(a) {
            return a.children('li').not('.mbsc-lv-back').not('.mbsc-lv-removed').not('.mbsc-lv-ph');
        }

        function ag(b) {
            if (typeof b !== 'object') {
                b = a('li[data-id="' + b + '"]', x);
            }
            return a(b);
        }

        function bN(c) {
            var b = 0,
                a = O[c.attr('data-ref')];
            while (a.ref) {
                b++;
                a = O[a.ref];
            }
            return b;
        }

        function aO(a, b) {
            a = a[b]();
            while (a.length && (!a.hasClass('mbsc-lv-item') || a.hasClass('mbsc-lv-ph') || a.hasClass('mbsc-lv-item-dragging'))) {
                if (!g.sortable.group && a.hasClass('mbsc-lv-gr-title')) {
                    return false;
                }
                a = a[b]();
            }
            return a;
        }

        function bE(a) {
            return (a > 0 ? y.right : y.left).color || p;
        }

        function _(a) {
            return c.isNumeric(a) ? a + '' : 0;
        }

        function bG(a, b) {
            return +(b < 0 ? _((a.actionsWidth || 0).right) || _(a.actionsWidth) || _(v.actionsWidth.right) || _(v.actionsWidth) : _((a.actionsWidth || 0).left) || _(a.actionsWidth) || _(v.actionsWidth.left) || _(v.actionsWidth));
        }

        function aj(c, e) {
            if (c) {
                var b = B.scrollTop(),
                    d = c.is('.mbsc-lv-item') ? c[0].offsetHeight : 0,
                    a = c.offset().top + (W ? b - b7 : 0);
                if (e) {
                    if (a < b || a > b + aa) {
                        B.scrollTop(a);
                    }
                } else {
                    if (a < b) {
                        B.scrollTop(a);
                    } else if (a + d > b + aa) {
                        B.scrollTop(a + d - aa / 2);
                    }
                }
            }
        }

        function bb(e, a, b, c, f) {
            var g = a.parent(),
                d = a.prev();
            c = c || i;
            if (d[0] === N[0]) {
                d = N.prev();
            }
            if (K[0] !== a[0]) {
                A('onNavStart', {
                    level: a4,
                    direction: e,
                    list: a[0]
                });
                b3.prepend(a.addClass('mbsc-lv-v mbsc-lv-sl-new'));
                aj(x);
                bK(b3, 'mbsc-lv-sl-' + e, function() {
                    K.removeClass('mbsc-lv-sl-curr');
                    a.removeClass('mbsc-lv-sl-new').addClass('mbsc-lv-sl-curr');
                    if (aJ && aJ.length) {
                        K.removeClass('mbsc-lv-v').insertAfter(aJ);
                    } else {
                        at.append(K.removeClass('mbsc-lv-v'));
                    }
                    aJ = d;
                    at = g;
                    K = a;
                    aj(b, f);
                    c.call(G, b);
                    A('onNavEnd', {
                        level: a4,
                        direction: e,
                        list: a[0]
                    });
                });
            } else {
                aj(b, f);
                c.call(G, b);
            }
        }

        function bc(a, b) {
            if (!X) {
                if (a.hasClass('mbsc-lv-parent')) {
                    a4++;
                    bb('r', O[a.attr('data-ref')].child, null, b);
                } else if (a.hasClass('mbsc-lv-back')) {
                    a4--;
                    bb('l', O[a.attr('data-back')].parent, O[a.attr('data-back')].item, b);
                }
            }
        }

        function bK(a, c, b) {
            var e;

            function d() {
                clearTimeout(e);
                X--;
                a.off(m, d).removeClass(c);
                b.call(G, a);
            }
            b = b || i;
            if (v.animation && c !== 'mbsc-lv-item-none') {
                X++;
                a.on(m, d).addClass(c);
                e = setTimeout(d, 500);
            } else {
                b.call(G, a);
            }
        }

        function bd(a, b) {
            var c, d = a.attr('data-ref');
            c = aE[d] = aE[d] || [];
            if (b) {
                c.push(b);
            }
            if (a.attr('data-action')) {
                return;
            }
            b = c.shift();
            a.attr('data-action', 1);
            b(function() {
                a.removeAttr('data-action');
                if (c.length) {
                    bd(a);
                } else {
                    delete aE[d];
                }
            });
        }

        function be(c, e, g) {
            var d, b;
            if (c && c.length) {
                d = 100 / (c.length + 2);
                a.each(c, function(h, a) {
                    if (a.key === f) {
                        a.key = b5++;
                    }
                    if (a.percent === f) {
                        a.percent = e * d * (h + 1);
                        if (g) {
                            b = t({}, a);
                            b.key = b5++;
                            b.percent = -d * (h + 1);
                            c.push(b);
                            ap[b.key] = b;
                        }
                    }
                    ap[a.key] = a;
                });
            }
        }
        k.Base.call(this, bB, bH, true);
        g.animate = function(a, b, c) {
            bK(a, 'mbsc-lv-item-' + b, c);
        };
        g.add = function(y, s, h, p, w, l) {
            var r, m, q, u, k, o, n = '',
                c = w === f ? C : ag(w),
                d = c,
                b = typeof s !== 'object' ? a('<li data-ref="' + j++ + '" data-id="' + y + '">' + s + '</li>') : s,
                t = b.attr('data-pos') < 0 ? 'left' : 'right',
                e = b.attr('data-ref');
            p = p || i;
            if (!e) {
                e = j++;
                b.addClass('mbsc-lv-item').attr('data-ref', e);
            }
            by(b);
            if (!l) {
                g.addUndoAction(function(a) {
                    if (u) {
                        g.navigate(c, function() {
                            d.remove();
                            c.removeClass('mbsc-lv-parent').children('.mbsc-lv-arr').remove();
                            k.child = c.children('ul,ol');
                            g.remove(b, null, a, true);
                        });
                    } else {
                        g.remove(b, null, a, true);
                    }
                }, true);
            }
            bd(b, function(i) {
                a9(b.css('top', '').removeClass('mbsc-lv-item-undo'));
                if (c.is('li')) {
                    o = c.attr('data-ref');
                    if (!c.children('ul,ol').length) {
                        u = true;
                        c.append('<ul></ul>');
                    }
                } else {
                    o = c.children('.mbsc-lv-back').attr('data-back');
                }
                k = O[o];
                if (k) {
                    if (!k.child.length) {
                        c.addClass('mbsc-lv-parent').prepend(b9);
                        d = c.children('ul,ol').prepend(aV).addClass('mbsc-lv');
                        k.child = d;
                        a('.mbsc-lv-back', c).attr('data-back', o);
                    } else {
                        d = k.child;
                    }
                }
                O[e] = {
                    item: b,
                    child: b.children('ul,ol'),
                    parent: d,
                    ref: o
                };
                q = am(d);
                m = q.length;
                if (h === f || h === null) {
                    h = m;
                }
                if (l) {
                    n = 'mbsc-lv-item-new-' + (l ? t : '');
                }
                bz(b.addClass(n));
                if (h !== false) {
                    if (!m) {
                        r = a('.mbsc-lv-back', d);
                        if (r.length) {
                            b.insertAfter(r);
                        } else {
                            d.append(b);
                        }
                    } else if (h < m) {
                        b.insertBefore(q.eq(h));
                    } else {
                        b.insertAfter(q.eq(m - 1));
                    }
                }
                if (d.hasClass('mbsc-lv-v')) {
                    g.animate(b.height(b[0].offsetHeight), l && ay === e ? 'none' : 'expand', function(a) {
                        g.animate(a.height(''), l ? 'add-' + t : 'pop-in', function(a) {
                            p.call(G, a.removeClass(n));
                            i();
                        });
                    });
                } else {
                    p.call(G, b.removeClass(n));
                    i();
                }
                x.trigger('mbsc-enhance', [{
                    theme: v.theme,
                    lang: v.lang
                }]);
                A('onItemAdd', {
                    target: b[0]
                });
            });
        };
        g.swipe = function(a, d, b, e, g) {
            a = ag(a);
            u = a;
            aq = e;
            a7 = true;
            R = true;
            b = b === f ? 300 : b;
            J = d > 0 ? 1 : -1;
            bF();
            bL();
            ah(a, d, b);
            clearTimeout(bu);
            clearInterval(aS);
            aS = setInterval(function() {
                E = c.getPosition(a) / ae * 100;
                aW();
            }, 10);
            bu = setTimeout(function() {
                clearInterval(aS);
                E = d;
                aW();
                bf(g);
                aq = false;
                a7 = false;
                R = false;
            }, b);
        };
        g.openStage = function(b, a, c, d) {
            if (ap[a]) {
                g.swipe(b, ap[a].percent, c, d);
            }
        };
        g.openActions = function(a, c, d, e) {
            a = ag(a);
            var b = bG(af[a.attr('data-type') || 'defaults'], c == 'left' ? -1 : 1);
            g.swipe(a, c == 'left' ? -b : b, d, e);
        };
        g.close = function(a, b) {
            g.swipe(a, 0, b);
        };
        g.remove = function(a, d, b, e) {
            var f, c;
            b = b || i;
            a = ag(a);
            if (a.length) {
                c = a.parent();
                f = am(c).index(a);
                if (!e) {
                    if (a.attr('data-ref') === ay) {
                        aQ = true;
                    }
                    g.addUndoAction(function(b) {
                        g.add(null, a, f, b, c, true);
                    }, true);
                }
                bd(a, function(f) {
                    d = d || a.attr('data-pos') < 0 ? 'left' : 'right';
                    if (c.hasClass('mbsc-lv-v')) {
                        g.animate(a.addClass('mbsc-lv-removed'), e ? 'pop-out' : 'remove-' + d, function(a) {
                            g.animate(a.height(a[0].offsetHeight), 'collapse', function(a) {
                                a9(a.height('').removeClass('mbsc-lv-removed'));
                                if (b.call(G, a) !== false) {
                                    a.remove();
                                }
                                f();
                            });
                        });
                    } else {
                        if (b.call(G, a) !== false) {
                            a.remove();
                        }
                        f();
                    }
                    A('onItemRemove', {
                        target: a[0]
                    });
                });
            }
        };
        g.move = function(a, c, d, e, f, b) {
            a = ag(a);
            if (!b) {
                g.startActionTrack();
            }
            z.append(N);
            g.remove(a, d, null, b);
            g.add(null, a, c, e, f, b);
            if (!b) {
                g.endActionTrack();
            }
        };
        g.navigate = function(a, d) {
            var b, c;
            a = ag(a);
            b = O[a.attr('data-ref')];
            c = bN(a);
            if (b) {
                bb(c >= a4 ? 'r' : 'l', b.parent, a, d, true);
                a4 = c;
            }
        };
        g.init = function(q) {
            var m, o, h, p = C.find('ul,ol').length ? 'left' : 'right',
                d = 0,
                i = '',
                k = '',
                l = '';
            g._init(q);
            h = v.sort || v.sortable;
            if (h === 'group') {
                h = {
                    group: false,
                    multiLevel: true
                };
            }
            if (h === true) {
                h = {
                    group: true,
                    multiLevel: true,
                    handle: v.sortHandle
                };
            }
            if (h && h.handle === f) {
                h.handle = v.sortHandle;
            }
            g.sortable = h || false;
            m = 'mbsc-lv-cont mbsc-lv-' + v.theme + (v.rtl ? ' mbsc-lv-rtl' : '') + (v.baseTheme ? ' mbsc-lv-' + v.baseTheme : '') + (v.animateIcons ? ' mbsc-lv-ic-anim' : '') + (v.striped ? ' mbsc-lv-alt-row ' : '') + (v.fixedHeader ? ' mbsc-lv-has-fixed-header ' : '');
            if (!x) {
                i += '<div class="mbsc-lv-multi-c"></div>';
                i += '<div class="mbsc-lv-ic-c"><div class="mbsc-lv-ic-s mbsc-lv-ic mbsc-ic mbsc-ic-none"></div><div class="mbsc-lv-ic-text"></div></div>';
                C.addClass('mbsc-lv mbsc-lv-v mbsc-lv-root').show();
                z = a('<div class="mbsc-lv-stage-c">' + i + '</div>');
                N = a('.mbsc-lv-ic-c', z);
                aP = a('.mbsc-lv-multi-c', z);
                al = a('.mbsc-lv-ic-s', z);
                aF = a('.mbsc-lv-ic-text', z);
                Q = a('<li class="mbsc-lv-item mbsc-lv-ph"></li>');
                as = a('<div class="mbsc-lv-fill-item"></div>');
                x = a('<div class="' + m + '"><ul class="mbsc-lv mbsc-lv-dummy"></ul><div class="mbsc-lv-sl-c"></div></div>');
                W = v.context !== 'body';
                B = a(W ? v.context : n);
                bq = a('.mbsc-lv-dummy', x);
                x.insertAfter(C);
                B.on('orientationchange resize', aZ);
                aZ();
                x.on('touchstart mousedown', '.mbsc-lv-item', bP).on('touchmove', '.mbsc-lv-item', aU).on('touchend touchcancel', '.mbsc-lv-item', ao);
                if (G.addEventListener) {
                    G.addEventListener('click', function(a) {
                        if (aL) {
                            a.stopPropagation();
                            a.preventDefault();
                            aL = false;
                        }
                    }, true);
                }
                x.on('touchstart mousedown', '.mbsc-lv-ic-m', function(a) {
                    if (!aq) {
                        a.stopPropagation();
                        a.preventDefault();
                    }
                    ax = b(a, 'X');
                    au = b(a, 'Y');
                }).on('touchend mouseup', '.mbsc-lv-ic-m', function(d) {
                    if (!aq) {
                        if (d.type === 'touchend') {
                            c.preventClick();
                        }
                        if (e && !a(this).hasClass('mbsc-lv-ic-disabled') && Math.abs(b(d, 'X') - ax) < 10 && Math.abs(b(d, 'Y') - au) < 10) {
                            a$((E < 0 ? y.rightMenu : y.leftMenu)[a(this).index()], bx, bw);
                        }
                    }
                });
                b3 = a('.mbsc-lv-sl-c', x).append(C.addClass('mbsc-lv-sl-curr')).attr('data-ref', j++);
                K = C;
                at = x;
            } else {
                x.attr('class', m);
                if (g.sortable.handle) {
                    a('.mbsc-lv-handle-c', C).remove();
                }
                a('li:not(.mbsc-lv-back)', C).removeClass('mbsc-lv-item');
            }
            aV = '<li class="mbsc-lv-item mbsc-lv-back">' + v.backText + '<div class="mbsc-lv-arr mbsc-lv-ic mbsc-ic ' + v.leftArrowClass + '"></div></li>';
            b9 = '<div class="mbsc-lv-arr mbsc-lv-ic mbsc-ic ' + v.rightArrowClass + '"></div>';
            if (g.sortable.handle) {
                aR = g.sortable.handle === true ? p : g.sortable.handle;
                bt = '<div class="mbsc-lv-handle-c mbsc-lv-item-h-' + aR + ' mbsc-lv-handle"><div class="' + v.handleClass + ' mbsc-lv-handle-bar-c mbsc-lv-handle">' + v.handleMarkup + '</div></div>';
                x.addClass('mbsc-lv-handle-' + aR);
            }
            bz(C);
            b5 = 0;
            af = v.itemGroups || {};
            af.defaults = {
                swipeleft: v.swipeleft,
                swiperight: v.swiperight,
                stages: v.stages,
                actions: v.actions,
                actionsWidth: v.actionsWidth
            };
            a.each(af, function(c, b) {
                b.swipe = b.swipe !== f ? b.swipe : v.swipe;
                b.stages = b.stages || [];
                be(b.stages, 1, true);
                be(b.stages.left, 1);
                be(b.stages.right, -1);
                if (b.stages.left || b.stages.right) {
                    b.stages = [].concat(b.stages.left || [], b.stages.right || []);
                }
                aw = false;
                if (!b.stages.length) {
                    if (b.swipeleft) {
                        b.stages.push({
                            percent: -30,
                            action: b.swipeleft
                        });
                    }
                    if (b.swiperight) {
                        b.stages.push({
                            percent: 30,
                            action: b.swiperight
                        });
                    }
                }
                a.each(b.stages, function(b, a) {
                    if (a.percent === 0) {
                        aw = true;
                        return false;
                    }
                });
                if (!aw) {
                    b.stages.push({
                        percent: 0
                    });
                }
                b.stages.sort(function(a, b) {
                    return a.percent - b.percent;
                });
                a.each(b.stages, function(a, c) {
                    if (c.percent === 0) {
                        b.start = a;
                        return false;
                    }
                });
                if (aw) {
                    b.left = b.right = b.stages[b.start];
                } else {
                    b.left = b.stages[b.start - 1] || {};
                    b.right = b.stages[b.start + 1] || {};
                }
                if (b.actions) {
                    b.leftMenu = b.actions.left || b.actions;
                    b.rightMenu = b.actions.right || b.leftMenu;
                    k = '';
                    l = '';
                    for (d = 0; d < b.leftMenu.length; d++) {
                        k += '<div ' + (b.leftMenu[d].color ? 'style="background-color: ' + b.leftMenu[d].color + '"' : '') + ' class="mbsc-lv-ic-m mbsc-lv-ic mbsc-ic mbsc-ic-' + b.leftMenu[d].icon + '">' + (b.leftMenu[d].text || '') + '</div>';
                    }
                    for (d = 0; d < b.rightMenu.length; ++d) {
                        l += '<div ' + (b.rightMenu[d].color ? 'style="background-color: ' + b.rightMenu[d].color + '"' : '') + ' class="mbsc-lv-ic-m mbsc-lv-ic mbsc-ic mbsc-ic-' + b.rightMenu[d].icon + '">' + (b.rightMenu[d].text || '') + '</div>';
                    }
                    if (b.actions.left) {
                        b.swipe = b.actions.right ? b.swipe : 'right';
                    }
                    if (b.actions.right) {
                        b.swipe = b.actions.left ? b.swipe : 'left';
                    }
                    b.icons = '<div class="mbsc-lv-multi mbsc-lv-multi-ic-left">' + k + '</div><div class="mbsc-lv-multi mbsc-lv-multi-ic-right">' + l + '</div>';
                }
            });
            if (v.fixedHeader) {
                o = 'mbsc-lv-fixed-header' + (W ? ' mbsc-lv-fixed-header-ctx mbsc-lv-' + v.theme + (v.baseTheme ? ' mbsc-lv-' + v.baseTheme : '') : '');
                if (!U) {
                    U = a('<div class="' + o + '"></div>');
                    if (W) {
                        B.before(U);
                    } else {
                        x.prepend(U);
                    }
                    b1 = c.throttle(bO, 200);
                    B.on('scroll touchmove', b1);
                } else {
                    U.attr('class', o);
                }
            }
            if (v.hover) {
                if (!aG) {
                    x.on('mouseover.mbsc-lv', '.mbsc-lv-item', function() {
                        if (!$ || $[0] != this) {
                            bi();
                            $ = a(this);
                            if (af[$.attr('data-type') || 'defaults'].actions) {
                                bI = setTimeout(function() {
                                    if (!aH) {
                                        aY = true;
                                        g.openActions($, bm, aG, false);
                                    } else {
                                        $ = null;
                                    }
                                }, bk);
                            }
                        }
                    }).on('mouseleave.mbsc-lv', bi);
                }
                aG = v.hover.time || 200;
                bk = v.hover.timeout || 200;
                bm = v.hover.direction || v.hover || 'right';
            }
            if (C.is('[mbsc-enhance]')) {
                bp = true;
                C.removeAttr('mbsc-enhance');
                x.attr('mbsc-enhance', '');
            }
            x.trigger('mbsc-enhance', [{
                theme: v.theme,
                lang: v.lang
            }]);
            A('onInit');
        };
        g.destroy = function() {
            at.append(K);
            if (W && U) {
                U.remove();
            }
            if (bp) {
                C.attr('mbsc-enhance', '');
            }
            x.find('.mbsc-lv-txt,.mbsc-lv-img').removeClass('mbsc-lv-txt mbsc-lv-img');
            x.find('ul,ol').removeClass('mbsc-lv mbsc-lv-v mbsc-lv-root mbsc-lv-sl-curr').find('li').removeClass('mbsc-lv-gr-title mbsc-lv-item mbsc-lv-item-enhanced mbsc-lv-parent mbsc-lv-img-left mbsc-lv-img-right mbsc-lv-item-ic-left mbsc-lv-item-ic-right').removeAttr('data-ref');
            a('.mbsc-lv-back,.mbsc-lv-handle-c,.mbsc-lv-arr,.mbsc-lv-item-ic', x).remove();
            C.insertAfter(x);
            x.remove();
            z.remove();
            B.off('scroll touchmove', b1).off('orientationchange resize', aZ);
            g._destroy();
        };
        var aN, a_ = [],
            a5 = [],
            aC = [],
            ad = 0;
        g.startActionTrack = function() {
            if (!ad) {
                aC = [];
            }
            ad++;
        };
        g.endActionTrack = function() {
            ad--;
            if (!ad) {
                a5.push(aC);
            }
        };
        g.addUndoAction = function(b, c) {
            var a = {
                action: b,
                async: c
            };
            if (ad) {
                aC.push(a);
            } else {
                a5.push([a]);
                if (a5.length > v.undoLimit) {
                    a5.shift();
                }
            }
        };
        g.undo = function() {
            var a, b, c;

            function d() {
                if (b < 0) {
                    aN = false;
                    e();
                } else {
                    a = c[b];
                    b--;
                    if (a.async) {
                        a.action(d);
                    } else {
                        a.action();
                        d();
                    }
                }
            }

            function e() {
                c = a_.shift();
                if (c) {
                    aN = true;
                    b = c.length - 1;
                    d();
                }
            }
            if (a5.length) {
                a_.push(a5.pop());
            }
            if (!aN) {
                e();
            }
        };
        v = g.settings;
        A = g.trigger;
        g.init(bH);
    };
    k.ListView.prototype = {
        _class: 'listview',
        _hasDef: true,
        _hasTheme: true,
        _hasLang: true,
        _defaults: {
            context: 'body',
            actionsWidth: 90,
            sortDelay: 250,
            undoLimit: 10,
            swipe: true,
            quickSwipe: true,
            animateIcons: true,
            animation: true,
            revert: true,
            vibrate: true,
            handleClass: '',
            handleMarkup: '<div class="mbsc-lv-handle-bar mbsc-lv-handle"></div><div class="mbsc-lv-handle-bar mbsc-lv-handle"></div><div class="mbsc-lv-handle-bar mbsc-lv-handle"></div>',
            leftArrowClass: 'mbsc-ic-arrow-left4',
            rightArrowClass: 'mbsc-ic-arrow-right4',
            backText: 'Back',
            undoText: 'Undo',
            stages: []
        }
    };
    g.themes.listview.mobiscroll = {
        leftArrowClass: 'mbsc-ic-arrow-left5',
        rightArrowClass: 'mbsc-ic-arrow-right5'
    };
    g.presetShort('listview', 'ListView');
}(window, document));
(function() {
    mobiscroll.themes.listview.ios = {
        leftArrowClass: 'mbsc-ic-ion-ios7-arrow-back',
        rightArrowClass: 'mbsc-ic-ion-ios7-arrow-forward'
    };
}());
(function() {
    mobiscroll.themes.listview.jqm = {
        handleClass: 'ui-btn ui-icon-bars ui-btn-up-c ui-btn-icon-notext ui-icon-shadow ui-corner-all ui-btn-corner-all',
        handleMarkup: '<span class="ui-btn-inner mbsc-lv-handle"><span class="ui-icon ui-icon-bars ui-icon-shadow mbsc-lv-handle">&nbsp;</span></span>',
        leftArrowClass: 'ui-btn-icon-left ui-icon-carat-l',
        rightArrowClass: 'ui-btn-icon-right ui-icon-carat-r',
        onInit: function() {
            $(this).closest('.mbsc-lv-cont').addClass($(this).data('inset') ? 'mbsc-lv-jqm-inset' : '').find('.mbsc-lv-dummy, .mbsc-lv-fixed-header').addClass('ui-listview');
            $('ul,ol', this).listview('refresh');
        },
        onItemAdd: function(b) {
            var a = $(b.target).parent();
            if (a.hasClass('ui-listview')) {
                a.listview('refresh');
            } else {
                a.listview();
            }
        },
        onSortUpdate: function(a) {
            $(a.target).parent().listview('refresh');
        }
    };
}());
(function() {
    var a = mobiscroll,
        b = a.$;
    a.themes.listview.material = {
        leftArrowClass: 'mbsc-ic-material-keyboard-arrow-left',
        rightArrowClass: 'mbsc-ic-material-keyboard-arrow-right',
        onItemActivate: function(c) {
            a.themes.material.addRipple(b(c.target), c.domEvent);
        },
        onItemDeactivate: function() {
            a.themes.material.removeRipple();
        },
        onSlideStart: function(a) {
            b('.mbsc-ripple', a.target).remove();
        },
        onSortStart: function(a) {
            b('.mbsc-ripple', a.target).remove();
        }
    };
}());